package com.fzrskj.cloud.free.user.utils;

import com.fzrskj.cloud.free.user.dao.AlertRecordNoRepeatDao;
import com.fzrskj.cloud.free.user.bean.AlertRecordNoRepeatBean;
import ms.core.object.CObject;
import org.apache.commons.collections.map.HashedMap;

import java.util.Map;

/**
 * AlertRecordNoRepeatUtils.
 *
 * @author zj.
 *         Created on 2018/12/17 0017.
 */
public class AlertRecordNoRepeatUtils extends CObject {
    //private declarations
    private AlertRecordNoRepeatDao dao=null;

    //constructor function to initialize database access object
    public AlertRecordNoRepeatUtils(){ dao=new AlertRecordNoRepeatDao(); }

    //to free resource
    @Override
    public void dispose(){
        if (dao!=null) {
            dao.dispose();
        }
        dao = null;
        super.dispose();
    }

    /**
     * 是否不存在.
     * @param kind kind.
     * @param keyIndex keyIndex.
     * @return Boolean
     */
    public Boolean exist(Integer kind, String keyIndex) {
        AlertRecordNoRepeatBean repeatBean = this.dao.queryAlertRecordNoRepeat(kind, keyIndex);
        if (null == repeatBean) {
            Map<String, Object> data = new HashedMap();
            data.put("kind", kind);
            data.put("keyIndex", keyIndex);
            this.dao.newAlertRecordNoRepeat(data);
            return false;
        }
        return true;
    }

    /**
     * 是否不存在.
     * @param kind kind
     * @param keyIndex keyIndex
     * @return Boolean.
     */
    public static Boolean isExists(Integer kind, String keyIndex) {
        AlertRecordNoRepeatUtils repeatUtils = new AlertRecordNoRepeatUtils();
        return repeatUtils.exist(kind, keyIndex);
    }
}
